//
//  UIAlertController+ShowMessage.m
//  CaiPiao-JS
//
//  Created by apple on 2017/6/13.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "UIAlertController+ShowMessage.h"
#import "LEEAlert.h"
@implementation UIAlertController (ShowMessage)

+(UIAlertController*)showAlert:(NSString*)message {
    UIAlertController* actionAlert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
    [actionAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"OK",@"InfoPlist", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    return actionAlert;
}

+(UIAlertController*)showAlert:(NSString*)message andDoneAction:(AlertDoneAction)AlertDone{
    UIAlertController* actionAlert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
    [actionAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"Cancel",@"InfoPlist", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [actionAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"OK",@"InfoPlist", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (AlertDone) {
            AlertDone();
        }
    }]];
    return actionAlert;
}

+(UIAlertController*)showAlertWithTitle:(NSString*)title andMessage:(NSString*)message andDoneAction:(AlertDoneAction)AlertDone{
    UIAlertController* actionAlert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [actionAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"Cancel",@"InfoPlist", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [actionAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"OK",@"InfoPlist", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (AlertDone) {
            AlertDone();
        }
    }]];
    return actionAlert;
}





//
///***
// headerColor
// textColor
// actionTitleColor
// actionBackgroundColor
// ***/
//
//
+(void)showConfirmWithColorStyle:(NSDictionary*)colorStyle Title:(NSString*)title Message:(NSString*)message andDoneAction:(AlertDoneAction)AlertDone andCancelAction:(AlertCancleAction)AlertCancle{
    UIColor *blueColor = [UIColor colorWithRed:90/255.0f green:154/255.0f blue:239/255.0f alpha:1.0f];


    UIColor* headerColor = blueColor;
    UIColor* textColor = [UIColor whiteColor];
    UIColor* actionTitleColor = blueColor;
    UIColor* actionBackgroundColor = [UIColor whiteColor];

    if (colorStyle[@"headerColor"]) {
        headerColor = colorStyle[@"headerColor"];
    }

    if (colorStyle[@"textColor"]) {
        textColor = colorStyle[@"textColor"];
    }

    if (colorStyle[@"actionTitleColor"]) {
        actionTitleColor = colorStyle[@"actionTitleColor"];
    }

    if (colorStyle[@"actionBackgroundColor"]) {
        actionBackgroundColor = colorStyle[@"actionBackgroundColor"];
    }

    [LEEAlert alert].config
    .LeeAddTitle(^(UILabel *label) {

        label.text = title;

        label.textColor = textColor;
    })
    .LeeAddContent(^(UILabel *label) {

        label.text = message;

        label.textColor = [textColor colorWithAlphaComponent:0.9f];
    })
    .LeeAddAction(^(LEEAction *action) {

        action.type = LEEActionTypeCancel;

        action.title = NSLocalizedStringFromTable(@"取消",@"InfoPlist", nil);

        action.titleColor = actionTitleColor;

        action.backgroundColor = actionBackgroundColor;

        action.clickBlock = ^{
            if (AlertCancle) {
                AlertCancle();
            }
            // 取消点击事件Block
        };
    })
    .LeeAddAction(^(LEEAction *action) {

        action.type = LEEActionTypeDefault;

        action.title = NSLocalizedStringFromTable(@"退出",@"InfoPlist", nil);

        action.titleColor = actionTitleColor;

        action.backgroundColor = actionBackgroundColor;

        action.clickBlock = ^{
            if (AlertDone) {
                AlertDone();
            }
        };
    })
    .LeeHeaderColor(headerColor)
    .LeeShow();
}

+(void)showAlertWithColorStyle:(NSDictionary*)colorStyle Title:(NSString*)title Message:(NSString*)message andDoneAction:(AlertDoneAction)AlertDone{
    UIColor *blueColor = [UIColor colorWithRed:90/255.0f green:154/255.0f blue:239/255.0f alpha:1.0f];


    UIColor* headerColor = blueColor;
    UIColor* textColor = [UIColor whiteColor];
    UIColor* actionTitleColor = blueColor;
    UIColor* actionBackgroundColor = [UIColor whiteColor];

    if (colorStyle[@"headerColor"]) {
        headerColor = colorStyle[@"headerColor"];
    }

    if (colorStyle[@"textColor"]) {
        textColor = colorStyle[@"textColor"];
    }

    if (colorStyle[@"actionTitleColor"]) {
        actionTitleColor = colorStyle[@"actionTitleColor"];
    }

    if (colorStyle[@"actionBackgroundColor"]) {
        actionBackgroundColor = colorStyle[@"actionBackgroundColor"];
    }

    [LEEAlert alert].config
    .LeeAddTitle(^(UILabel *label) {

        label.text = title;

        label.textColor = textColor;
    })
    .LeeAddContent(^(UILabel *label) {

        label.text = message;

        label.textColor = [textColor colorWithAlphaComponent:0.9f];
    })
    .LeeAddAction(^(LEEAction *action) {

        action.type = LEEActionTypeDefault;

        action.title = NSLocalizedStringFromTable(@"OK",@"InfoPlist", nil);

        action.titleColor = actionTitleColor;

        action.backgroundColor = actionBackgroundColor;
        action.clickBlock = ^{
            if (AlertDone) {
                AlertDone();
            }
        };
    })
    .LeeHeaderColor(headerColor)
    .LeeShow();
}


@end
